#include "log.h"

#include "log4cplus/logger.h"
#include "log4cplus/configurator.h"
#include <log4cplus/loggingmacros.h>

#include <memory>
using namespace log4cplus;

namespace CodingSea {

static std::shared_ptr<ConfigureAndWatchThread> g_configWatchThread;

static Logger g_Logger = Logger::getRoot();

void LogProxy::Init(const TString& config_file)
{
    std::locale::global(std::locale("chs"));
    initialize();
    g_configWatchThread.reset(new ConfigureAndWatchThread(config_file, 5 * 1000));
    g_Logger = Logger::getRoot();
}

void LogProxy::Trace(const TString& str)
{
    LOG4CPLUS_TRACE(g_Logger, str);
}

void LogProxy::Debug(const TString& str)
{
    LOG4CPLUS_DEBUG(g_Logger, str);
}

void LogProxy::Info(const TString& str)
{
    LOG4CPLUS_INFO(g_Logger, str);
}

void LogProxy::Warn(const TString& str)
{
    LOG4CPLUS_WARN(g_Logger, str);
}

void LogProxy::Error(const TString& str)
{
    LOG4CPLUS_ERROR(g_Logger, str);
}

void LogProxy::Fatal(const TString& str)
{
    LOG4CPLUS_FATAL(g_Logger, str);
}

void LogProxy::Uninit()
{
    g_configWatchThread = nullptr;
    Logger::shutdown();
    // log4cplus::threadCleanup();
    deinitialize();
}

} // namespace CodingSea